]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
cleanup: Minimize deep_unpack() usage
authorAlessandro Bono <alessandro.bono369@gmail.com>
Wed, 10 Aug 2022 09:44:42 +0000 (11:44 +0200)
committerMarge Bot <marge-bot@gnome.org>
Wed, 10 Aug 2022 10:29:24 +0000 (10:29 +0000)
deep_unpack()[1] will unpack a variant and its children, but only up to one level.
lookup_value()[2] will directly search for a value with a linear scan.

Performing a deep_unpack() + lookup can be a more expensive operation when we are
looking for just a single value compared to just perform the lookup_value() directly
in C. Avoid the deep_unpack() usage when we perform a single check presence.

[1] https://gjs.guide/guides/glib/gvariant.html#deepunpack
[2] https://docs.gtk.org/glib/method.Variant.lookup_value.html

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2416>

js/gdm/realmd.js
js/misc/modemManager.js
js/misc/smartcardManager.js
js/ui/status/location.js
js/ui/status/nightLight.js
js/ui/status/powerProfiles.js
js/ui/status/thunderbolt.js

index e8220462ec96a0de2360593d4380760460121cd3..52661c1e54da943e52075b52f777a8a940e8b827 100644 (file)
@@ -28,7 +28,8 @@ var Manager = class extends Signals.EventEmitter {
 
         this._aggregateProvider.connectObject('g-properties-changed',
             (proxy, properties) => {
-                if ('Realms' in properties.deep_unpack())
+                const realmsChanged = !!properties.lookup_value('Realms', null);
+                if (realmsChanged)
                     this._reloadRealms();
             }, this);
     }
@@ -67,7 +68,8 @@ var Manager = class extends Signals.EventEmitter {
         this._reloadRealm(realm);
 
         realm.connect('g-properties-changed', (proxy, properties) => {
-            if ('Configured' in properties.deep_unpack())
+            const configuredChanged = !!properties.lookup_value('Configured', null);
+            if (configuredChanged)
                 this._reloadRealm(realm);
         });
     }
index 0325ee6b34d92161b3d724ae568225f86ceca448..0424b77ff9f8d322f8e74be752cc85bdaa2f51ee 100644 (file)
@@ -243,7 +243,8 @@ var BroadbandModem = GObject.registerClass({
         this._proxy_cdma = new BroadbandModemCdmaProxy(Gio.DBus.system, 'org.freedesktop.ModemManager1', path);
 
         this._proxy.connect('g-properties-changed', (proxy, properties) => {
-            if ('SignalQuality' in properties.deep_unpack())
+            const signalQualityChanged = !!properties.lookup_value('SignalQuality', null);
+            if (signalQualityChanged)
                 this._reloadSignalQuality();
         });
         this._reloadSignalQuality();
index 851cc445f8852f0d85940fed493aed25c55f21d3..661b337710c358f3ee19c98b27c2113452fc1e11 100644 (file)
@@ -73,7 +73,8 @@ var SmartcardManager = class extends Signals.EventEmitter {
         this._updateToken(token);
 
         token.connect('g-properties-changed', (proxy, properties) => {
-            if ('IsInserted' in properties.deep_unpack()) {
+            const isInsertedChanged = !!properties.lookup_value('IsInserted', null);
+            if (isInsertedChanged) {
                 this._updateToken(token);
 
                 if (token.IsInserted)
index 116272d157ef40399450ba499d8e9fa95d9c0f7f..2115e5c231f6964b2f6cf5036667b38175938e7a 100644 (file)
@@ -181,8 +181,8 @@ var GeoclueAgent = GObject.registerClass({
     }
 
     _onGeocluePropsChanged(proxy, properties) {
-        let unpacked = properties.deep_unpack();
-        if ("InUse" in unpacked)
+        const inUseChanged = !!properties.lookup_value('InUse', null);
+        if (inUseChanged)
             this.notify('in-use');
     }
 
index a7fa92a3fc2976d29f261b9c2aeb8c9a2f727745..1a0ee303a3f8dd5a96fa9eaa01c2756619711b5a 100644 (file)
@@ -49,7 +49,8 @@ class Indicator extends SystemIndicator {
             g_interface_info: colorInfo,
         });
         this._proxy.connect('g-properties-changed', (p, properties) => {
-            if ('NightLightActive' in properties.deep_unpack())
+            const nightLightActiveChanged = !!properties.lookup_value('NightLightActive', null);
+            if (nightLightActiveChanged)
                 this._sync();
         });
         this._proxy.init_async(GLib.PRIORITY_DEFAULT, null)
index f1745e9953c73a284258aff2041627d87f6cf11d..43f6ce93f3b7adefd0cf837bde3380bd7099f697 100644 (file)
@@ -52,13 +52,12 @@ class PowerProfilesToggle extends QuickMenuToggle {
                 if (error) {
                     log(error.message);
                 } else {
-                    this._proxy.connect('g-properties-changed',
-                        (p, properties) => {
-                            const propertyNames = properties.deep_unpack();
-                            if ('Profiles' in propertyNames)
-                                this._syncProfiles();
-                            this._sync();
-                        });
+                    this._proxy.connect('g-properties-changed', (p, properties) => {
+                        const profilesChanged = !!properties.lookup_value('Profiles', null);
+                        if (profilesChanged)
+                            this._syncProfiles();
+                        this._sync();
+                    });
                     this._syncProfiles();
                 }
                 this._sync();
index afe3a6195865cdb7ff53011d6bbe72dc1fe748d6..2e1236e594287c65947b2cfe53c93abcb976fca6 100644 (file)
@@ -83,12 +83,11 @@ var Client = class extends Signals.EventEmitter {
     }
 
     _onPropertiesChanged(proxy, properties) {
-        let unpacked = properties.deep_unpack();
-        if (!('Probing' in unpacked))
-            return;
-
-        this.probing = this._proxy.Probing;
-        this.emit('probing-changed', this.probing);
+        const probingChanged = !!properties.lookup_value('Probing', null);
+        if (probingChanged) {
+            this.probing = this._proxy.Probing;
+            this.emit('probing-changed', this.probing);
+        }
     }
 
     _onDeviceAdded(proxy, emitter, params) {